package finalproject.model.player;

import java.util.List;

import finalproject.config.Randomizer;
import finalproject.model.studies.Lab;
import finalproject.model.studies.Lecture;

/**
 * 
 * @author tijani Yassine
 *
 */
public class CourseBook {

    private List<Lecture> lectures;
    private List<Lab> labs;
    /**
     * create a coursebook
     * @param lectures
     * @param labs
     */
    public CourseBook(List<Lecture> lectures, List<Lab> labs)
    {
        this.lectures = lectures;
        this.labs =  labs;
    }
    /**
     * 
     * @return the list of the lectures
     */
    public List<Lecture> getLectures() {
        return lectures;
    }
    /**
     * set the list of lectures
     * @param lectures
     */
    public void setLectures(List<Lecture> lectures) {
        this.lectures = lectures;
    }
    /**
     * 
     * @return the list of labs
     */
    public List<Lab> getLabs() {
        return labs;
    }
    /**
     * set the list of labs
     * @param labs
     */
    public void setLabs(List<Lab> labs) {
        this.labs = labs;
    }
    /**
     * 
     * @param the name of the lecture
     * @return true if the lecture was removed, false if not
     */
    public boolean removeLectureOf(String name)
    {
     for(int i=0;i<lectures.size();i++)
     {
         if(lectures.get(i).getTitle().equals(name))
         {
             removeLabOf(lectures.get(i).getLabSession().getTitle());
             lectures.remove(i);
             return true;
         }
     }
     return false;
    }
    /**
     * 
     * @param the name of the lab
     * @return true if lab was removed, false if not
     */
    public boolean removeLabOf(String name)
    {
        for(int i=0;i<labs.size();i++)
        {
            if(labs.get(i).getTitle().equals(name))
            {
                labs.remove(i);
                return true;
            }
        }
        return false;      
    }
    /**
     * 
     * @param list of all Lectures
     * @return Lecture undone
     */
    public  Lecture getUndoneCourse(List<Lecture> allLectures)
    {
        if(lectures.size() == 0)
        {
            return allLectures.get(Randomizer.getRandom().nextInt(allLectures.size()));
        }
        for(Lecture lect : allLectures)
        {
            for(int i=0;i<lectures.size();i++)
            {
                if(!(lectures.get(i).getTitle().equals(lect.getTitle())))
                {
                return lect;
                }
            }
        }
        return null;
    }
    /**
     * 
     * @param list of all Labs
     * @return Lab undone
     */ 
    public  Lab getUndoneLab(List<Lab> allLabs)
    {
        if(labs.size() == 0)
        {
            return allLabs.get(Randomizer.getRandom().nextInt(allLabs.size()));
        }
        for(Lab lab : allLabs)
        {
            for(int i=0;i<labs.size();i++)
            {
            if(!labs.get(i).getTitle().equals(lab.getTitle()))
            {
                return lab;
            }
            }
        }
        return null;        
    }
}
